package org.hyh.transactional;

import com.alibaba.fastjson.JSON;
import org.hyh.autowired.TestAdmin;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import javax.annotation.Priority;
import java.util.List;
import java.util.Map;

/**
 * @auther :hyh
 * @desc :
 * @date :2019/12/17
 */
@Service
@Priority(100)
//@Import(TestOtherImport.class)
public class AccountImpl  implements  IAcount {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private ApplicationContext  ac;

//	private IAcount accountProxy;

	@Autowired
	private IAcount acount;


//	@PostConstruct
//	public  void  getAccountImpl() {
//		accountProxy = ac.getBean(IAcount.class);
//	}


	static  String  insertSql="insert into  account values (?,?,?)";
	static  String  reduceSql="update account set  money=? where name=?";
	@TestAdmin
	@Override
	@Transactional
	public void saveMoney() {

		int update = jdbcTemplate.update(insertSql,3,"永健",600);
		System.out.println(update);
		System.out.println("--------");
		try {
			acount.reduceMoney();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	@Transactional(propagation = Propagation.REQUIRES_NEW)
	@Override
	public void reduceMoney() {

		int update = jdbcTemplate.update(insertSql,4,"永健",600);
		System.out.println(update);
		int i=10/0;
	}


	@Override
	public String toString() {
		return "AccountImpl{" +
				"jdbcTemplate=" + jdbcTemplate +
				'}';
	}


}
